<h1 id="控制语句">控制语句</h1>
<p>Quick 包含以下控制语句：</p>
<ul>
<li>if 条件控制语句</li>
<li>for  一般循环</li>
<li>foreach 索引，值遍历</li>
<li>fori 索引遍历</li>
<li>forv 值遍历</li>
<li>break 中止整个循环／遍历</li>
<li>continue 中止循环／遍历的当前轮的程序执行</li>
<li>return 函数返回</li>
</ul>
<h4 id="示例一">示例一</h4>
<pre><code class="hljs language-javascript">arr = [<span class="hljs-number">1</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">true</span>, <span class="hljs-number">3.14</span>, <span class="hljs-string">&quot;changlie&quot;</span>]
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;### normal: &quot;</span>)
foreach i, item : arr {
    <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;index:&quot;</span>, i, <span class="hljs-string">&quot;; item:&quot;</span>, item)
}
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;### abnormal: &quot;</span>)
foreach i, item : arr {
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span> {
        <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;index:&quot;</span>, i, <span class="hljs-string">&quot;; item:&quot;</span>, item, <span class="hljs-string">&quot; #continue&quot;</span>)
        <span class="hljs-keyword">continue</span>
    }
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">3</span> {
        <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;index:&quot;</span>, i, <span class="hljs-string">&quot;; item:&quot;</span>, item, <span class="hljs-string">&quot; #break&quot;</span>)
        <span class="hljs-keyword">break</span>
    }
    <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;index:&quot;</span>, i, <span class="hljs-string">&quot;; item:&quot;</span>, item)
}
</code></pre>
<p>输出</p>
<pre><code>### normal: 
index: 0 ; item: 1
index: 1 ; item: false
index: 2 ; item: true
index: 3 ; item: 3.14
index: 4 ; item: changlie
### abnormal: 
index: 0 ; item: 1
index: 1 ; item: false  #continue
index: 2 ; item: true
index: 3 ; item: 3.14  #break
</code></pre>
<h4 id="示例二">示例二</h4>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;2 -&gt; &quot;</span>, <span class="hljs-title function_">fprint</span>(<span class="hljs-number">2</span>))
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;===================&quot;</span>)
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;4 -&gt; &quot;</span>, <span class="hljs-title function_">fprint</span>(<span class="hljs-number">4</span>))

<span class="hljs-title function_">fprint</span>(<span class="hljs-params">flag</span>) {
    sum = <span class="hljs-number">0</span>
    <span class="hljs-keyword">for</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">10</span>; i++ {
        sum += i
        <span class="hljs-keyword">if</span> flag == i {
            <span class="hljs-keyword">return</span> sum
        }
    }
    <span class="hljs-keyword">return</span> sum
}
</code></pre>
<p>输出</p>
<pre><code>2 -&gt;  3
===================
4 -&gt;  10
</code></pre>
<h4 id="示例三">示例三</h4>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;ftest below -----------------&quot;</span>)
<span class="hljs-title function_">ftest</span>(<span class="hljs-number">3</span>, <span class="hljs-literal">false</span>)
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;===================&quot;</span>)
<span class="hljs-title function_">ftest</span>(<span class="hljs-number">4</span>, <span class="hljs-literal">true</span>)

<span class="hljs-title function_">ftest</span>(<span class="hljs-params">flag, exit</span>) {
    <span class="hljs-keyword">for</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">20</span>; i++ {

        <span class="hljs-keyword">if</span> i%flag == <span class="hljs-number">2</span> {
            <span class="hljs-title function_">println</span>(i, <span class="hljs-string">&quot; -&gt; execute continue&quot;</span>)
            <span class="hljs-keyword">continue</span>
        }
        <span class="hljs-keyword">if</span> exit &amp;&amp; i == <span class="hljs-number">4</span>  {
            <span class="hljs-title function_">println</span>(i, <span class="hljs-string">&quot; -&gt; execute return&quot;</span>)
            <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
        }
        <span class="hljs-keyword">if</span> i &gt; <span class="hljs-number">9</span> {
            <span class="hljs-title function_">println</span>(i, <span class="hljs-string">&quot; -&gt; execute break&quot;</span>)
            <span class="hljs-keyword">break</span>
        }
        <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;row -&gt; &quot;</span>, i)
    }
    <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;func over!&quot;</span>)
}
</code></pre>
<p>输出</p>
<pre><code>ftest below -----------------
row -&gt;  0
row -&gt;  1
2  -&gt; execute continue
row -&gt;  3
row -&gt;  4
5  -&gt; execute continue
row -&gt;  6
row -&gt;  7
8  -&gt; execute continue
row -&gt;  9
10  -&gt; execute break
func over!
===================
row -&gt;  0
row -&gt;  1
2  -&gt; execute continue
row -&gt;  3
4  -&gt; execute return
</code></pre>
<h4 id="示例四">示例四</h4>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;doubleLoopTest below----------------&quot;</span>)
<span class="hljs-title function_">doubleLoopTest</span>(<span class="hljs-number">4</span>, <span class="hljs-literal">false</span>)
<span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;=========================&quot;</span>)
<span class="hljs-title function_">doubleLoopTest</span>(<span class="hljs-number">4</span>, <span class="hljs-literal">true</span>)

<span class="hljs-title function_">doubleLoopTest</span>(<span class="hljs-params">num, flag</span>) {
    <span class="hljs-keyword">for</span> i=<span class="hljs-number">1</span>; i&lt;<span class="hljs-number">5</span>; i++ {
        <span class="hljs-keyword">for</span> j=<span class="hljs-number">1</span>; j&lt;<span class="hljs-number">12</span>; j++ {
            <span class="hljs-keyword">if</span> i*j == <span class="hljs-number">9</span> {
                <span class="hljs-title function_">println</span>(i, j, <span class="hljs-string">&quot;-&gt; continue&quot;</span>)
                <span class="hljs-keyword">continue</span>
            }
            <span class="hljs-keyword">if</span> flag &amp;&amp; j == <span class="hljs-number">4</span> {
                <span class="hljs-title function_">println</span>(i, j, <span class="hljs-string">&quot;-&gt; return 0&quot;</span>)
                <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
            }
            <span class="hljs-keyword">if</span> j == num {
                <span class="hljs-title function_">println</span>(i, j, <span class="hljs-string">&quot;-&gt; break&quot;</span>)
                <span class="hljs-keyword">break</span>
            }
            <span class="hljs-title function_">println</span>(i, j, <span class="hljs-string">&quot;-&gt; normal&quot;</span>)
        }
    }
    <span class="hljs-title function_">println</span>(<span class="hljs-string">&quot;func over!&quot;</span>)
}
</code></pre>
<p>输出</p>
<pre><code>doubleLoopTest below----------------
1 1 -&gt; normal
1 2 -&gt; normal
1 3 -&gt; normal
1 4 -&gt; break
2 1 -&gt; normal
2 2 -&gt; normal
2 3 -&gt; normal
2 4 -&gt; break
3 1 -&gt; normal
3 2 -&gt; normal
3 3 -&gt; continue
3 4 -&gt; break
4 1 -&gt; normal
4 2 -&gt; normal
4 3 -&gt; normal
4 4 -&gt; break
func over!
=========================
1 1 -&gt; normal
1 2 -&gt; normal
1 3 -&gt; normal
1 4 -&gt; return 0
</code></pre>
